﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Himp.Erp.Migrations
{
    /// <inheritdoc />
    public partial class add_table_MaterialInventory : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "InboundRecDetls",
                schema: "Erp");

            migrationBuilder.DropColumn(
                name: "ArrivalDatetime",
                schema: "Erp",
                table: "InboundRecs");

            migrationBuilder.DropColumn(
                name: "BillingDatetime",
                schema: "Erp",
                table: "InboundRecs");

            migrationBuilder.DropColumn(
                name: "DiscountAmt",
                schema: "Erp",
                table: "InboundRecs");

            migrationBuilder.DropColumn(
                name: "DiscountRate",
                schema: "Erp",
                table: "InboundRecs");

            migrationBuilder.RenameColumn(
                name: "PurchaseDatetime",
                schema: "Erp",
                table: "InboundRecs",
                newName: "InboundDatetime");

            migrationBuilder.RenameColumn(
                name: "PurchaseAmt",
                schema: "Erp",
                table: "InboundRecs",
                newName: "InboundAmt");

            migrationBuilder.RenameColumn(
                name: "InvoiceNo",
                schema: "Erp",
                table: "InboundRecs",
                newName: "DyntNo");

            migrationBuilder.RenameColumn(
                name: "InboundOrderNo",
                schema: "Erp",
                table: "InboundRecs",
                newName: "OrderNo");

            migrationBuilder.CreateTable(
                name: "InboundDetls",
                schema: "Erp",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    InboundRecId = table.Column<Guid>(type: "uuid", nullable: false),
                    MaterialInfoId = table.Column<Guid>(type: "uuid", nullable: false),
                    IndexNo = table.Column<int>(type: "integer", nullable: false),
                    Pric = table.Column<decimal>(type: "numeric(18,6)", nullable: false),
                    Cnt = table.Column<decimal>(type: "numeric(18,4)", nullable: false),
                    Amt = table.Column<decimal>(type: "numeric(18,6)", nullable: false),
                    ManuLotnum = table.Column<string>(type: "text", nullable: false),
                    ManuDate = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
                    TrdnFlag = table.Column<bool>(type: "boolean", nullable: false),
                    ValiDatetime = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
                    Bchno = table.Column<string>(type: "text", nullable: false),
                    Exp = table.Column<string>(type: "text", nullable: true),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_InboundDetls", x => x.Id);
                    table.ForeignKey(
                        name: "FK_InboundDetls_InboundRecs_InboundRecId",
                        column: x => x.InboundRecId,
                        principalSchema: "Erp",
                        principalTable: "InboundRecs",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_InboundDetls_MaterialInfos_MaterialInfoId",
                        column: x => x.MaterialInfoId,
                        principalSchema: "Erp",
                        principalTable: "MaterialInfos",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "MaterialAppyRecs",
                schema: "Erp",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    AppyNo = table.Column<string>(type: "text", nullable: false),
                    AppyDate = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
                    AppyCatgeCodg = table.Column<string>(type: "text", nullable: false),
                    AppyCatgeName = table.Column<string>(type: "text", nullable: false),
                    AppyDeptId = table.Column<Guid>(type: "uuid", nullable: false),
                    AppyDeptCodg = table.Column<string>(type: "text", nullable: false),
                    AppyDeptName = table.Column<string>(type: "text", nullable: false),
                    AppyStas = table.Column<int>(type: "integer", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true),
                    ExtraProperties = table.Column<string>(type: "text", nullable: false),
                    ConcurrencyStamp = table.Column<string>(type: "character varying(40)", maxLength: 40, nullable: false),
                    CreationTime = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
                    CreatorId = table.Column<Guid>(type: "uuid", nullable: true),
                    LastModificationTime = table.Column<DateTime>(type: "timestamp without time zone", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "uuid", nullable: true),
                    IsDeleted = table.Column<bool>(type: "boolean", nullable: false, defaultValue: false),
                    DeleterId = table.Column<Guid>(type: "uuid", nullable: true),
                    DeletionTime = table.Column<DateTime>(type: "timestamp without time zone", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MaterialAppyRecs", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "MaterialInventorys",
                schema: "Erp",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    MaterialWhseId = table.Column<Guid>(type: "uuid", nullable: false),
                    MaterialInfoId = table.Column<Guid>(type: "uuid", nullable: false),
                    TrdnFlag = table.Column<bool>(type: "boolean", nullable: false),
                    BatchNo = table.Column<string>(type: "text", nullable: false),
                    InvType = table.Column<int>(type: "integer", nullable: false),
                    OrderNo = table.Column<string>(type: "text", nullable: false),
                    ValidityDate = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
                    CurFlag = table.Column<bool>(type: "boolean", nullable: false),
                    Ver = table.Column<long>(type: "bigint", nullable: false),
                    TotalCnt = table.Column<decimal>(type: "numeric(18,2)", nullable: false),
                    OrderCnt = table.Column<decimal>(type: "numeric(18,2)", nullable: false),
                    FinlCnt = table.Column<decimal>(type: "numeric(18,2)", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true),
                    ExtraProperties = table.Column<string>(type: "text", nullable: false),
                    ConcurrencyStamp = table.Column<string>(type: "character varying(40)", maxLength: 40, nullable: false),
                    CreationTime = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
                    CreatorId = table.Column<Guid>(type: "uuid", nullable: true),
                    LastModificationTime = table.Column<DateTime>(type: "timestamp without time zone", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "uuid", nullable: true),
                    IsDeleted = table.Column<bool>(type: "boolean", nullable: false, defaultValue: false),
                    DeleterId = table.Column<Guid>(type: "uuid", nullable: true),
                    DeletionTime = table.Column<DateTime>(type: "timestamp without time zone", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MaterialInventorys", x => x.Id);
                    table.ForeignKey(
                        name: "FK_MaterialInventorys_MaterialInfos_MaterialInfoId",
                        column: x => x.MaterialInfoId,
                        principalSchema: "Erp",
                        principalTable: "MaterialInfos",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_MaterialInventorys_MaterialWhses_MaterialWhseId",
                        column: x => x.MaterialWhseId,
                        principalSchema: "Erp",
                        principalTable: "MaterialWhses",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "MaterialAppyDetls",
                schema: "Erp",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    MaterialAppyRecId = table.Column<Guid>(type: "uuid", nullable: false),
                    MaterialInfoID = table.Column<Guid>(type: "uuid", nullable: false),
                    Cnt = table.Column<decimal>(type: "numeric", nullable: false),
                    Exp = table.Column<string>(type: "text", nullable: true),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MaterialAppyDetls", x => x.Id);
                    table.ForeignKey(
                        name: "FK_MaterialAppyDetls_MaterialAppyRecs_MaterialAppyRecId",
                        column: x => x.MaterialAppyRecId,
                        principalSchema: "Erp",
                        principalTable: "MaterialAppyRecs",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_MaterialAppyDetls_MaterialInfos_MaterialInfoID",
                        column: x => x.MaterialInfoID,
                        principalSchema: "Erp",
                        principalTable: "MaterialInfos",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_InboundDetls_InboundRecId",
                schema: "Erp",
                table: "InboundDetls",
                column: "InboundRecId");

            migrationBuilder.CreateIndex(
                name: "IX_InboundDetls_MaterialInfoId",
                schema: "Erp",
                table: "InboundDetls",
                column: "MaterialInfoId");

            migrationBuilder.CreateIndex(
                name: "IX_MaterialAppyDetls_MaterialAppyRecId",
                schema: "Erp",
                table: "MaterialAppyDetls",
                column: "MaterialAppyRecId");

            migrationBuilder.CreateIndex(
                name: "IX_MaterialAppyDetls_MaterialInfoID",
                schema: "Erp",
                table: "MaterialAppyDetls",
                column: "MaterialInfoID");

            migrationBuilder.CreateIndex(
                name: "IX_MaterialInventorys_MaterialInfoId",
                schema: "Erp",
                table: "MaterialInventorys",
                column: "MaterialInfoId");

            migrationBuilder.CreateIndex(
                name: "IX_MaterialInventorys_MaterialWhseId",
                schema: "Erp",
                table: "MaterialInventorys",
                column: "MaterialWhseId");
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "InboundDetls",
                schema: "Erp");

            migrationBuilder.DropTable(
                name: "MaterialAppyDetls",
                schema: "Erp");

            migrationBuilder.DropTable(
                name: "MaterialInventorys",
                schema: "Erp");

            migrationBuilder.DropTable(
                name: "MaterialAppyRecs",
                schema: "Erp");

            migrationBuilder.RenameColumn(
                name: "OrderNo",
                schema: "Erp",
                table: "InboundRecs",
                newName: "InboundOrderNo");

            migrationBuilder.RenameColumn(
                name: "InboundDatetime",
                schema: "Erp",
                table: "InboundRecs",
                newName: "PurchaseDatetime");

            migrationBuilder.RenameColumn(
                name: "InboundAmt",
                schema: "Erp",
                table: "InboundRecs",
                newName: "PurchaseAmt");

            migrationBuilder.RenameColumn(
                name: "DyntNo",
                schema: "Erp",
                table: "InboundRecs",
                newName: "InvoiceNo");

            migrationBuilder.AddColumn<DateTime>(
                name: "ArrivalDatetime",
                schema: "Erp",
                table: "InboundRecs",
                type: "timestamp without time zone",
                nullable: true);

            migrationBuilder.AddColumn<DateTime>(
                name: "BillingDatetime",
                schema: "Erp",
                table: "InboundRecs",
                type: "timestamp without time zone",
                nullable: true);

            migrationBuilder.AddColumn<decimal>(
                name: "DiscountAmt",
                schema: "Erp",
                table: "InboundRecs",
                type: "numeric(18,4)",
                nullable: true);

            migrationBuilder.AddColumn<decimal>(
                name: "DiscountRate",
                schema: "Erp",
                table: "InboundRecs",
                type: "numeric(18,2)",
                nullable: true);

            migrationBuilder.CreateTable(
                name: "InboundRecDetls",
                schema: "Erp",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    InboundRecId = table.Column<Guid>(type: "uuid", nullable: false),
                    MaterialInfoId = table.Column<Guid>(type: "uuid", nullable: false),
                    BatchNo = table.Column<string>(type: "text", nullable: false),
                    DiscountAmt = table.Column<decimal>(type: "numeric(18,4)", nullable: false),
                    DiscountRate = table.Column<decimal>(type: "numeric(18,4)", nullable: false),
                    DiscountUnitPrice = table.Column<decimal>(type: "numeric(18,4)", nullable: false),
                    Exp = table.Column<string>(type: "text", nullable: true),
                    InboundStas = table.Column<int>(type: "integer", nullable: false),
                    ManuLotnum = table.Column<string>(type: "text", nullable: false),
                    ManufactureDatetime = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
                    PurchaseAmt = table.Column<decimal>(type: "numeric(18,4)", nullable: false),
                    PurchaseQuantity = table.Column<decimal>(type: "numeric(18,4)", nullable: false),
                    PurchaseUnitPrice = table.Column<decimal>(type: "numeric(18,4)", nullable: false),
                    RtalAmt = table.Column<decimal>(type: "numeric(18,4)", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true),
                    TotalRtalAmt = table.Column<decimal>(type: "numeric(18,4)", nullable: false),
                    TrdnFlag = table.Column<bool>(type: "boolean", nullable: false),
                    ValiDatetime = table.Column<DateTime>(type: "timestamp without time zone", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_InboundRecDetls", x => x.Id);
                    table.ForeignKey(
                        name: "FK_InboundRecDetls_InboundRecs_InboundRecId",
                        column: x => x.InboundRecId,
                        principalSchema: "Erp",
                        principalTable: "InboundRecs",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_InboundRecDetls_MaterialInfos_MaterialInfoId",
                        column: x => x.MaterialInfoId,
                        principalSchema: "Erp",
                        principalTable: "MaterialInfos",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_InboundRecDetls_InboundRecId",
                schema: "Erp",
                table: "InboundRecDetls",
                column: "InboundRecId");

            migrationBuilder.CreateIndex(
                name: "IX_InboundRecDetls_MaterialInfoId",
                schema: "Erp",
                table: "InboundRecDetls",
                column: "MaterialInfoId");
        }
    }
}
